import book.Book;
import book.Library;
import user.User;
import user.factory.AdminUserFactory;
import user.factory.IUserFactory;
import user.factory.NormalUserFactory;
import user.factory.ProxyUser;
import utils.ScannerSingleton;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Scanner;

public class LibrarySystem {

    public static void main(String[] args) throws IOException {
        //工厂模式
        IUserFactory adminFactory = new AdminUserFactory();
        User admin = adminFactory.createUser("管理员",1);

        IUserFactory normalFactory = new NormalUserFactory();
        User normal = normalFactory.createUser("普通用户",2);

        //代理模式
        ProxyUser adminProxy = new ProxyUser(admin);
        ProxyUser normalProxy = new ProxyUser(normal);

        Book[] books = new Book[4];
//        books[0] = new Book("西游记","吴承恩",1900, LocalDateTime.of(2023,4,23,0,0));
//        books[1] = new Book("水浒传","施耐庵",1923, LocalDateTime.of(2022,6,5,0,0));
//        books[2] = new Book("三国演义","罗贯中",1937, LocalDateTime.of(2020,9,14,0,0));
//        books[3] = new Book("红楼梦","曹雪芹",1947, LocalDateTime.of(2021,3,1,0,0));

        LibrarySystem librarySystem = new LibrarySystem();
        ProxyUser currentUser = librarySystem.selectProxyRole(adminProxy,normalProxy);

        while(true){
            int choice = currentUser.display();

            currentUser.handleOperation(choice);

        }


}

    private ProxyUser selectProxyRole(ProxyUser adminProxy, ProxyUser normalProxy) {
            System.out.println("请选择你的身份：");
            System.out.println("1.管理员\n2.普通用户\n0.退出系统");
            ProxyUser currentUser = null;

            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    currentUser = adminProxy;
                    break;
                case 2:
                    currentUser = normalProxy;
                    break;
                case 0:
                    System.out.println("退出系统");
                    System.exit(0);
                default:
                    break;
            }

            return currentUser;
        }
}
